﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Common;

namespace BLL {
    public class Contact {
        SQLDAL.Contact dal = new SQLDAL.Contact();
        public int GetContactCountByGroupId(int groupId) {
            return dal.GetContactCountByGroupId(groupId);
        }
        public DataTable GetList(string strWhere) {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 业务逻辑：判断填写的信息是否正确
        /// </summary>
        /// <param name="model"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool CheckModel(Model.Contact model,out string msg) {
            bool check = true;
            msg = "";
            if (model.Name == "") {
                check = false;
                msg = "联系人姓名不能为空。";
                return check;
            }
            if (!Utility.CheckMobilePhone(model.Phone)) {
                check = false;
                msg = "手机号码不正确！";
                return check;
            }
            if (!Utility.CheckMail(model.Email)) {
                check = false;
                msg = "邮箱地址不正确！";
                return check;
            }
            if (!Utility.CheckQQ(model.QQ)) {
                check = false;
                msg = "QQ号码不正确！";
                return check;
            }
            if (!Utility.CheckPhone(model.OfficePhone)) {
                check = false;
                msg = "办公电话不正确。";
                return check;
            }
            if (!Utility.CheckPhone(model.HomePhone)) {
                check = false;
                msg = "家庭电话不正确。";
                return check;
            }
            return check;
        }
        public bool Add(Model.Contact model,out string message) {
            if (!CheckModel(model,out message)) {
                return false;
            }
            else {
                return dal.Add(model);
            }
        }
        public bool Delete(int Id) {
            return dal.Delete(Id);
        }
        public bool Update(Model.Contact model,out string msg) {
            if (!CheckModel(model,out msg)) {
                return false;
            }
            else {
                return dal.Update(model);
            }
        }
        public Model.Contact GetModel(int Id) {
            return dal.GetModel(Id);
        }
    }
}
